<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>

    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>多条件搜索</legend>
            <div class="layui-form layui-form-pane" lay-filter="orderForm1">
                <input hidden id="goodsNo" type="text" name="goodsNo">
                <div class="layui-form-item">
                    <label class="layui-form-label">出/入库</label>
                    <div id="status" class="layui-input-block">
                        <input type="checkbox"   name="status1"  value="in"  title="入库单据" >
                        <input type="checkbox"   name="status2" value="out"  title="出库单据" >
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="margin-right:9px">起始时间</label>
                    <div class="layui-input-block" style="margin: 5px">
                        <input type="date" name= "start" class="layui-date layui-btn layui-btn-primary" >
                        <input type="date" name= "end"   class="layui-date layui-btn layui-btn-primary" >
                        <tip>比较规则：2020-11-23 00:00:00 - 2020-11-26 00:00:00 (包含启始时间)</tip>
                    </div>
                </div>
            </div>
        </fieldset>
        <div class="layui-inline" style = "margin-top:8px">
            <button id="resetTable" type="button" class="layui-btn layui-btn-sm layui-btn-warm">重置表格</button>
            <button id='searchbtn1' type="button" class="layui-btn layui-btn-sm "  ><i class="layui-icon"></i> 搜索并统计</button>
        </div>
        <div class="layui-inline" style = "margin-top:8px">
            <label class="layui-form-label"> 入库总量 </label>
            <div class="layui-input-block">
                <input disabled type="text"  id="sumin" name= "sumin" value="0" class="layui-input" >
            </div>
        </div>
        <div class="layui-inline" style = "margin-top:8px">
            <label class="layui-form-label"> 出库总量 </label>
            <div class="layui-input-block">
                <input  disabled type="text" id="sumout" name= "sumout"  value="0" class="layui-input" >
            </div>
        </div>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
</div>
<table class="layui-hide" id="orderDetail"    lay-filter="currentTableFilter" ></table>

<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>

<script type="text/html" id="currentTableBar">
    <input  type= "button" value = "编辑" class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="editOrder">
    <input  type= "button" value=  "撤销订单" class="layui-btn layui-btn-xs layui-btn-danger data-count-delete"  lay-event= "delete" >
</script>

<script type="text/html" id='goodsFormsInOut'>
    <div  class="layui-form layuimini-form" lay-filter="goodsFormsInOut">
        <div class="layui-form-item">
            <input type='text' name = 'orderNo' value=""  hidden >
            <label class="layui-form-label required">商品编号</label>
            <div class="layui-input-block">
                <input  disabled type="text" name="goodsNo"  lay-verify="required"  value="" class="layui-btn layui-btn-primary">
                <tip sytle="color:red">不可编辑</tip>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">商品名称</label>
            <div class="layui-input-block">
                <input  disabled type="text" name="goodsName"  lay-verify="required"  value="" class="layui-btn layui-btn-primary">
                <tip sytle="color:red">不可编辑</tip>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">生产厂家/订货商家</label>
            <div class="layui-input-block">
                <input   type="text" name="factory" lay-verify="required" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">尺寸</label>
            <div class="layui-input-block">
                <input  disabled type="text" name="standard" lay-verify="required"   value="" class="layui-btn layui-btn-primary">
                <tip sytle="color:red">不可编辑</tip>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">材质</label>
            <div class="layui-input-block">
                <input  disabled  type="text" name="material" lay-verify="required" value="" class="layui-btn layui-btn-primary">
                <tip sytle="color:red">不可编辑</tip>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label required">出/入库价格</label>
            <div class="layui-input-block">
                <input type="text" name="singlePrice" lay-verify="required" value="" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label required">数量</label>
            <div class="layui-input-block">
                <input  type="text" name="num" lay-verify="required" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">出/入日期</label>
            <div class="layui-input-block">
                <input type="date" name="dateio" value="" class="layui-date layui-btn layui-btn-primary" >
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">送/取货单位</label>
            <div class="layui-input-block">
                <input  type="text" name="unit" lay-verify="required" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">送/提货人姓名</label>
            <div class="layui-input-block">
                <input  type="text" name="personName" lay-verify="required" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">送/提货人电话</label>
            <div class="layui-input-block">
                <input  type="text" name="tel" lay-verify="required" value="" class="layui-input">
            </div>
        </div>


        <div class="layui-inline">
            <label class="layui-form-label">出/入库</label>
            <div class="layui-input-inline">
                <select name="statuss" id='sel' lay-verify="required" lay-search="">

                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button id="updateOrder" class="layui-btn layui-btn-normal">确认更新</button>
            </div>
        </div>
    </div>
</script>
<script>
	   layui.use(['form', 'layer','table'],function (){
             var $ = layui.jquery,
	         form = layui.form,
	         table = layui.table;
             form.render();
	         var datas  =   JSON.parse(sessionStorage.getItem('datas'));
           $('#goodsNo').val(datas.goodsNo);
           $('#resetTable').on('click',function () {
               $.ajax({
                   url: '/orders?action=selectSumByGoodsNo',
                   data: {goodsNo: datas.goodsNo },
                   type: 'get',
                   dataType: 'json',
                   success : function(result){
                       console.log(' this is result ************ ');
                       console.log(result);
                           if(result.data[0].sum> 0){
                               $("#sumin").val(result.data[0].sum);
                           }else {
                               $("#sumin").val('0');
                               $('#sumout').val(result.data[0].sum);
                           }
                           if(result.data.length>1){
                               $('#sumout').val(result.data[1].sum);
                           }
                   }
               });
                 table.render({
                     elem: '#orderDetail',
                     url:  '/orders?action=selectOrdersList',
                     where: {goodsNo: datas.goodsNo },
                     cols: [[
                         {field: 'dateio', width: 100, title: '出入日期' ,sort: true},
                         {field: 'goodsNo', width: 100, title: '商品类编号' ,sort: true},
                         {field: 'goodsName', width: 80, title: '商品名称' },
                         {field: 'standard', width: 80, title: '尺寸'},
                         {field: 'material', width: 80, title: '材质'},
                         {field: 'orderNo', width: 150, title: '单据编号'},
                         {field: 'factory', width: 150, title: '生产厂商/订货商家'},
                         {field: 'singlePrice', width: 60, title: '出/入库单价'},
                         {field: 'num', title: '数量', width:90 },
                         {field: 'datetime', width: 80, title: '创建时间' },
                         {field: 'unit', width: 100, title: '运送单位' },
                         {field: 'personName', width: 100, title: '送/取货人姓名'},
                         {field: 'tel', width: 100, title: '电话'},
                         {field: 'status', width: 100, title: '出/入库', sort:true},
                         {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
                     ]],
                     page: true,
                     limit: 5,
                     limits: [5,10,15,20,30,40,100],
                 });
             }).click();

           $('#searchbtn1').on('click',function (){
               var data = form.val('orderForm1');
               console.log(data);
               $.ajax({
                   url: '/orders?action=selectSumByGoodsNo',
                   data: data,
                   type: 'get',
                   dataType: 'json',
                   success : function(result){
                           if(result.data[0].sum> 0){
                               $("#sumin").val(result.data[0].sum);
                           }else {
                               $("#sumin").val('0');
                               $('#sumout').val(result.data[0].sum);
                           }
                           if(result.data.length>1){
                               $('#sumout').val(result.data[1].sum);
                           }
                   }
               });
               table.render({
                   elem: '#orderDetail',
                   url:  '/orders?action=selectOrdersList',
                   where: data,
                   cols: [[
                       {field: 'dateio', width: 100, title: '出入日期' ,sort: true},
                       {field: 'goodsNo', width: 100, title: '商品类编号' ,sort: true },
                       {field: 'goodsName', width: 80, title: '商品名称' },
                       {field: 'standard', width: 80, title: '尺寸'},
                       {field: 'material', width: 80, title: '材质'},
                       {field: 'orderNo', width: 150, title: '单据编号'},
                       {field: 'factory', width: 150, title: '生产厂商/订货商家'},
                       {field: 'singlePrice', width: 60, title: '出/入库单价'},
                       {field: 'num', title: '数量', width:90 },
                       {field: 'datetime', width: 80, title: '创建时间' },
                       {field: 'unit', width: 100, title: '运送单位' },
                       {field: 'personName', width: 100, title: '送/取货人姓名'},
                       {field: 'tel', width: 100, title: '电话'},
                       {field: 'status', width: 100, title: '出/入库', sort:true},
                       {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
                   ]],
                   page: true,
                   limit: 5,
                   limits: [5,10,15,20,30,40,100],
               });
           });
           table.on('tool(currentTableFilter)', function (obj) {
               var data = obj.data;
               console.log('this is data');
               console.log(data);
               if(obj.event==="editOrder"){
                   layer.open({
                       type:1 ,
                       content: $('#goodsFormsInOut').html(),
                       area:  ['60%','60%'],
                       title: '编辑单据',
                   });
                   if(data.status == "入库"){
                       $("#sel").append("<option selected value='"+  "in"  +"'> " + "入库"  +  "</option>");
                       $("#sel").append("<option  value='"+  "out"  +"'> " + "出库"  +  "</option>");
                   }else{
                       $("#sel").append("<option  value='"+  "in"  +"'> " + "入库"  +  "</option>");
                       $("#sel").append("<option selected value='"+  "out"  +"'> " + "出库"  +  "</option>");
                   }
                   form.val('goodsFormsInOut',data);
                   form.render();
               }else if(obj.event==="delete"){
                   layer.confirm('真的要删除吗？',function(){
                       layer.load(2);
                       $.post('/orders?action=deleteOrderByOrderNo', {orderNo:data.orderNo,goodsNo:data.goodsNo} ,function(){
                           console.log('this click **************');
                           layer.closeAll();
                           $('#resetTable').click();
                           $(window.parent.document).find("#resetTable").click();
                       });
                   });
               }
           });
           $('body').on('click','#updateOrder', function(){
               var data = form.val('goodsFormsInOut');
               console.log(data);
               layer.load(2);
               $.post('/orders?action=updateOrder', data , function(){
                   console.log('this ok');
                   $('#resetTable').click();
               //    form.render();
                   layer.closeAll();
                   $(window.parent.document).find("#resetTable").click();
               });
           });
       });
</script>
</body>
</html>